﻿using Microsoft.Practices.EnterpriseLibrary.Data.Sql;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using Easy.Common;

namespace Easy.DAL
{
   public class StringMapDAL
    {
         private readonly SqlDatabase sqldb = new SqlDatabase(Config.TulingBuyCrmConnectString);
         public StringMapDAL()
        {

        }
         public DataTable GetStringMap(String entityname, String attributename)
         {

             String Sql = "select value as text,attributevalue as value from StringMap where AttributeName=@attributename and EntityName=@entityname order by AttributeValue;";
             DbCommand comm = sqldb.GetSqlStringCommand(Sql);
             SqlParameter[] param = new SqlParameter[] { new SqlParameter("@attributename", attributename), new SqlParameter("@entityname", entityname) };
             comm.Parameters.AddRange(param);
             DataSet dt = sqldb.ExecuteDataSet(comm);
             return dt.Tables[0];

         }

         public DataTable GetGlobalMap(String globalname)
         {
             String Sql = "select value as text,attributevalue as value  from GlobalStringMap where Name=@globalname order by AttributeValue;";
             DbCommand comm = sqldb.GetSqlStringCommand(Sql);
             SqlParameter[] param = new SqlParameter[] { new SqlParameter("@globalname", globalname) };
             comm.Parameters.AddRange(param);
             DataSet dt = sqldb.ExecuteDataSet(comm);
             return dt.Tables[0];

         }

    }


}
